\documentclass[t,12pt,aspectratio=169]{beamer} % 16:9 宽屏比例，适合现代投影
\usepackage{ctex} % 中文支持
\usepackage{amsmath, amssymb} % 数学公式与符号
\usepackage{graphicx}
\usepackage{pythonhighlight}
\usepackage{url}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% 使表格美观
\usepackage{array}
\newcolumntype{M}[1]{>{\centering\arraybackslash}m{#1}}
%\newcolumntype{N}{@{}m{0pt}@{}}
\setlength\extrarowheight{3pt}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% 主题设置（推荐简洁风格）
\usetheme{Madrid}
\usecolortheme{default} % 可选：seahorse, beaver, dolphin 等

\title{多点测距定位 }
\author{五六七}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}

\begin{frame}
  \titlepage
\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}{内容提要 }


\begin{enumerate}\itemsep1em 

\item  已知平面上不同的观测站与未知位置的距离，求该未知的位置。

\item  在三维空间中考虑问题。

\end{enumerate}


\end{frame}%\vfill\hfill\thepage/\pageref{LastPage}\newpage


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}{目录}

\begin{enumerate}
\item  问题描述
\item  建立模型
\item  编程计算
\item  回答问题
%\item  

\end{enumerate}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}{1. 问题描述 }

\begin{itemize}\itemsep1em 

\item  
设在平面上考虑问题。已知四个观测站的位置坐标 $(x_i,y_i), \,\, i=1,2,3,4$. 
已知每个观测站到某个未知信号的距离 $d_i,\,\, i=1,2,3,4$. 求未知信号的位置坐标。

\begin{table}[ht]
\centering
%\caption{观测站的位置与测距}
\begin{tabular}{|M{3cm}|M{1.8cm}|M{1.8cm}|M{1.8cm}|M{1.8cm}|} \hline 
观测站编号&1&2&3&4 \\ \hline 
$x_i$ & 245 & 164 & 192 & 232  \\ \hline 
$y_i$ & 442 & 480 & 281 & 300 \\ \hline 
$d_i$ & 126.2204 & 120.7509 & 90.1854 & 101.4021  \\ \hline 
\end{tabular}
\end{table}

\end{itemize}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}{2.1. 建立模型  }

\begin{itemize}\itemsep1em 

\item  
设未知信号所在位置的坐标为 $(x,y)$. 则根据欧氏空间的距离公式，可得
\begin{eqnarray}
\sqrt{(x-x_1)^2+(y-y_1)^2} &=& d_1, \\ 
\sqrt{(x-x_2)^2+(y-y_2)^2} &=& d_2, \\ 
\sqrt{(x-x_3)^2+(y-y_3)^2} &=& d_3, \\ 
\sqrt{(x-x_4)^2+(y-y_4)^2} &=& d_4. 
\end{eqnarray}

\end{itemize}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}{2.2. 建立模型 }

\begin{itemize}\itemsep1em 

\item  
代入数据，可得关于未知数 $(x,y)$ 的四个方程。所以这是超定的方程组，一般求不出严格的解。
为了求出近似的数值解，我们考虑最小二乘法，把问题化为求下述函数的最小值，
\begin{eqnarray}
f(x,y) &=&  
\left[ \sqrt{(x-x_1)^2+(y-y_1)^2} - d_1\right]^2 \nonumber \\
&& + \left[ \sqrt{(x-x_2)^2+(y-y_2)^2} - d_2\right]^2  \nonumber \\ 
&& + \left[ \sqrt{(x-x_3)^2+(y-y_3)^2} - d_3\right]^2 \nonumber \\ 
&& + \left[ \sqrt{(x-x_4)^2+(y-y_4)^2} - d_4\right]^2.  
\end{eqnarray}

\end{itemize}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile]{3.1. 编程计算  }

\begin{itemize}\itemsep1em 

\item  
首先载入需要的程序包，以及最小二乘法优化函数 \texttt{least\_square}. 
\begin{python}
import numpy as np
from scipy.optimize import least_squares
\end{python}

\item  
输入已知的四个观测站的坐标数据，以及四个距离数据。
\begin{python}
x0=np.array([245,164,192,232])
y0=np.array([442,480,281,300])
d=np.array([126.2204,120.7509,90.1854,101.4021])
\end{python}

\end{itemize}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile]{3.2. 编程计算  }

\begin{itemize}\itemsep1em 

\item  
定义目标函数 fx, 注意函数的自变量为 x, 它有两个分量，分别是 x[0] 和 x[1]. 
注意到这个函数里并没有出现求和，但是变量 x0, y0 和 d 是前面定义的各自有四个分量的已知数值。
\begin{python}
fx=lambda x:np.sqrt((x0-x[0])**2+(y0-x[1])**2)-d
\end{python}

\item  
调用最小二乘法优化函数，自变量 x 的的两个分量的初始值都设为 0.5. 
\begin{python}
s=least_squares(fx, np.array([0.5,0.5]))
\end{python}

\end{itemize}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile]{3.3. 编程计算  }

\begin{itemize}\itemsep1em 

\item  
打印输出结果。
\begin{python}
print(s)
print(s.x)
\end{python}

\item  
查看变量 s 的数据类型，这是optimize 程序包自定义的数据类型。
\begin{python}
In[11]: type(s)
Out[11]: scipy.optimize.optimize.OptimizeResult
\end{python}

\end{itemize}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}{4.1. 回答问题 }

\begin{itemize}\itemsep1em 

\item  未知信号所在的坐标为 
\begin{eqnarray}
x &=& 149.5089, \\
y &=& 359.9848.
\end{eqnarray}

\item   画出四个观测站和未知信号的位置如下。
\begin{center}
\includegraphics [height=3cm, width=5cm]{five_points_four_lines.png}
\end{center}

\end{itemize}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile]{4.2. 画图使用代码 }

\begin{python}
import numpy as np
import matplotlib.pyplot as plt

x0=np.array([245,164,192,232])
y0=np.array([442,480,281,300])

x=149.5089 
y=359.9848

plt.plot(x0,y0,'bo')
plt.plot(x,y,'ro')
for k in range(4):
    plt.plot([x0[k],x],[y0[k],y],'b-')
\end{python}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}{参考文献 }

\begin{thebibliography}{1}

\bibitem{ssk2} 司守奎,孙玺菁. {Python数学建模算法与应用}, 国防工业出版社. 2022年1月第1版. 

\end{thebibliography}


\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\end{document}


